//
//  AboutUsViewController.m
//  PigMarket
//
//  Created by mac on 2019/3/23.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AboutUsViewController.h"
#import "SystemSetingCell.h"

@interface AboutUsViewController ()<UITableViewDelegate,UITableViewDataSource>

/**
 myTableView
 */
@property (nonatomic , strong) UITableView *myTableView;

/**
 dataArr
 */
@property (nonatomic , strong) NSArray *dataArr;

/**
 allRightLab
 */
@property (nonatomic , strong) UILabel *allRightLab;
@end

@implementation AboutUsViewController


#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.baseNavView.navTitleLabel.text = @"关于我们";
    [self setUpView];
}



#pragma mark - init method
- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}
- (void)initView {
    [self.view addSubview:self.myTableView];
    [self.view addSubview:self.allRightLab];
}

- (void) initLayout {
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.edges.mas_equalTo(TJ_NavBarHeight);
        make.top.mas_equalTo(TJ_NavBarHeight);
        make.right.left.bottom.mas_equalTo(self.view);
    }];
    [self.allRightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.myTableView.mas_centerX);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-IPHONEXBottomEdge);
    }];
}

- (void) initAction {
    
}

- (void)initData {
    self.dataArr = @[@{@"title":@"用户协议",@"detail":@""},
                     @{@"title":@"隐私政策",@"detail":@""},
                     @{@"title":@"免责声明",@"detail":@""},
                     @{@"title":@"激励政策",@"detail":@""},
                     @{@"title":@"版本更新",@"detail":@"已是最新版本"}];
}

#pragma mark - delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 220;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220)];
    
    UIImageView *logoImgView = [[UIImageView alloc] init];
    logoImgView.image = [UIImage imageNamed:@"login_logo"];
    [headerView addSubview:logoImgView];
    [logoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(50);
        make.centerX.mas_equalTo(headerView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(90, 90));
    }];
    UILabel *appNameLab = [[UILabel alloc] init];
    appNameLab.text = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    appNameLab.textColor = [UIColor textBlackColor];
    [headerView addSubview:appNameLab];
    [appNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(headerView.mas_centerX);
        make.top.mas_equalTo(logoImgView.mas_bottom).offset(14);
        make.height.mas_equalTo(24);
    }];
    UILabel *versionLab = [[UILabel alloc] init];
    versionLab.textColor = [UIColor colorWithHexString:@"#999999"];
    versionLab.font = [UIFont largerFont];
    versionLab.text = [NSString stringWithFormat:@"V%@",[infoDictionary objectForKey:@"CFBundleShortVersionString"]];
    [headerView addSubview:versionLab];
    [versionLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(headerView.mas_centerX);
        make.top.mas_equalTo(appNameLab.mas_bottom).offset(12);
        make.height.mas_equalTo(24);
    }];
    return headerView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SystemSetingCell *cell = [SystemSetingCell cellWithTableView:tableView];
    cell.infoDic = self.dataArr[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
#pragma mark - target action

#pragma mark - private method

#pragma mark - getter and setter
- (UITableView *)myTableView {
    if (!_myTableView) {
        _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableView.rowHeight = 54;
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
    }
    return _myTableView;
}
- (NSArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [[NSArray alloc] init];
    }
    return _dataArr;
}
- (UILabel *)allRightLab {
    if (!_allRightLab) {
        _allRightLab = [[UILabel alloc] init];
        _allRightLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _allRightLab.font = [UIFont smallFont];
        _allRightLab.text = @"Copyright © 2016年 xxx. All rights reserved";
    }
    return _allRightLab;
}
@end
